package com.desmart.renjiao.main.addresslist;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.desmart.renjiao.R;
import com.desmart.renjiao.bean.Company;
import com.desmart.renjiao.main.adapter.OrgainzationAdapter;
import com.lemon.library.common.ARoutePath;
import com.lemon.library.common.CommonFragment;

import java.util.ArrayList;
import java.util.List;

@Route(path = ARoutePath.Main.AddresslistFragment)
public class AddresslistFragment extends CommonFragment<AddresslistM,AddresslistP> implements View.OnClickListener,Addresslist.AddresslistV {

    private RecyclerView recyclerview;
    private List<Company> mList = new ArrayList<>();
    private OrgainzationAdapter mAdapter;

    @Override
    public int bindLayout() {
        return R.layout.fragment_main_addresslist;
    }

    @Override
    public void initView(View view) {
        view.findViewById(R.id.ll_phone_contact).setOnClickListener(this);
        recyclerview = view.findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
        mAdapter = new OrgainzationAdapter(mList);
        recyclerview.setAdapter(mAdapter);
    }

    @Override
    public void initData() {
        mPresenter.getOrgainzation();
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onNetStart(String tag, String startMsg) {
        super.onNetStart(tag, startMsg);
        showLoading();
    }

    @Override
    public void onSuccessGetOrgainzaiton(List<Company> list) {
        mList.clear();
        mList.addAll(list);
        mAdapter.notifyDataSetChanged();
    }
}
